package io.renren.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.app.dao.AppProductCategoryDao;
import io.renren.modules.app.entity.AppProductCategoryEntity;
import io.renren.modules.app.entity.dto.AppProductWithChildrenDTO;
import io.renren.modules.app.service.AppProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("appProductCategoryService")
public class AppProductCategoryServiceImpl extends ServiceImpl<AppProductCategoryDao, AppProductCategoryEntity> implements AppProductCategoryService {

    @Resource
    AppProductCategoryDao appProductCategoryDao;

    /**
     * 获取商品分类列表
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long parentId = Long.parseLong((String) params.getOrDefault("parentId","0"));

        IPage<AppProductCategoryEntity> page = this.page(
                new Query<AppProductCategoryEntity>().getPage(params),
                new QueryWrapper<AppProductCategoryEntity>()
                        .lambda().eq(AppProductCategoryEntity::getParentId,parentId)
        );

        return new PageUtils(page);
    }

    @Override
    public List<AppProductWithChildrenDTO> getWithChildren() {
        return appProductCategoryDao.getWithChildren();
    }
}
